import ScrollBarLayout from '@/components/ScrollBarLayout';
import Cls from 'classnames';
import { useContext, useEffect, useMemo, useState } from 'react';
import pageStyles from '@/common/pageLayout.less';
import { DescriptionsType } from '@/components/DescriptionsType';
import { CheckCircleOutlined, SaveOutlined } from '@ant-design/icons';
import { changeNumMoneyToChinese, wordHandChildParam, wordToChildParams } from '@/utils';
import { getUpdateConfig } from '../mconfig/UpdateConfig';
import { connect } from 'umi';
import { Col, Form, Row, Spin, message, Tabs, Modal, Space, Button } from 'antd';
import { getCurrentRouteObj } from '@/utils';
import React from 'react';

const UpdataMaterialModal: React.FC<any> = ({ curRes, locationProps }) => {
  /** 样式根目录 */
  const styleFixCls = 'contract-styfixcls-';

  /** 获取表单配置
   *  @leftSelectName    左侧仓库名称
   *  @record   当前项
   */
  let storageRouterObj: string | any = getCurrentRouteObj(); //获取解密后的当前页面路由数据
  const { config, methods } = getUpdateConfig({
    pageType: locationProps.state.pageType,
    record: locationProps?.state?.record ? locationProps?.state?.record : {},
  });

  // 暂存按钮
  const handleSave = () => {
    // 对表单进行校验，获取表单数据
    config.form.validateFields()?.then((values: any) => {
      message.success('暂存成功');
    });
  };

  // 暂存按钮
  const handleSubmit = () => {
    // 对表单进行校验，获取表单数据
    config.form.validateFields()?.then((values: any) => {
      message.success('提交成功');
    });
  };

  /** 返回tab子页面 */
  const tabsItem = useMemo(() => {
    let items: any[] = [
      {
        label: '添加退库',
        key: '001',
        children: (
          <div className="commonTabsBodyDom">
            <div className={Cls('tabsBodyInfoDom', `${styleFixCls}updateFormBox`)}>
              <ScrollBarLayout style={{ padding: '5px 20px' }}>
                <DescriptionsType config={config} />
              </ScrollBarLayout>
            </div>
            {locationProps?.state?.pageType != 'view' ? (
              <div className="tabsBodyBottomBtn">
                <Space>
                  <Button type={'primary'} icon={<SaveOutlined />} onClick={handleSave}>
                    暂存
                  </Button>
                  {locationProps?.state?.pageType == 'add' ? (
                    <Button type={'primary'} icon={<CheckCircleOutlined />} onClick={handleSubmit}>
                      提交
                    </Button>
                  ) : null}
                </Space>
              </div>
            ) : null}
          </div>
        ),
      },
    ];
    return items;
  }, []);

  // useEffect(()=>{
  //   console.log('123',storageRouterObj)
  // },[])

  return (
    <>
      <Spin spinning={false}>
        <Row className={`${styleFixCls}row`}>
          <Col span={24} className={`${styleFixCls}row-col`}>
            <Tabs className={pageStyles['commonTabs']} type="card" onChange={(activeKey: string) => {}} items={tabsItem} destroyInactiveTabPane={true} />
          </Col>
        </Row>
      </Spin>
    </>
  );
};

export default connect(({ baseLogin, navTab }: Record<string, any>) => ({
  curRes: baseLogin?.permissions,
  navTab,
}))(UpdataMaterialModal);
